package com.tanhua.test;

import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.tanhua.TanhuaAppServerApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TanhuaAppServerApplication.class)
public class FastDFSTest01 {

    //存储服务器
    @Autowired
    private FastFileStorageClient client;

    @Autowired
    private FdfsWebServer webServer;//获取存储服务器的请求地址

    @Test
    public  void testUpload() throws Exception{
        File file = new File("D:\\img\\05.mp4");
        //上传
        /**
         *
         *      * @param inputStream 流
         *      * @param fileSize 文件大小
         *      * @param fileExtName 文件后缀名
         *      * @param metaDataSet 文件的其他一些信息：作者、时间   可以null
         *
         */
        StorePath storePath = client.uploadFile(new FileInputStream(file), file.length(), "mp4", null);
        //打印地址
        System.out.println(webServer.getWebServerUrl());
        System.out.println(storePath.getFullPath());


    }


}
